package com.ym.controller.soso;

import com.github.pagehelper.PageInfo;
import com.ym.common.utils.page.PageDomain;
import com.ym.core.annotation.Log;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;
import com.ym.soso.domain.entity.PolyclinicEntity;
import com.ym.soso.domain.param.PolyclinicQueryParam;
import com.ym.soso.domain.param.PolyclinicUpdateParam;
import com.ym.soso.domain.vo.PolyclinicListPcVO;
import com.ym.soso.service.IPolyclinicSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

import static com.ym.common.constant.ValidRule.Add;
import static com.ym.common.constant.ValidRule.Update;

/**
 * 综合门诊 Controller
 * 
 * @author ym
 * @date 2020-09-02
 */
@Api(tags = "medical-综合门诊 ")
@RestController("PolyclinicPcController")
@Validated
@RequestMapping("/medical/polyclinic")
public class PolyclinicController extends BaseController {

    @Autowired
    private IPolyclinicSV polyclinicSV;

    @ApiOperation("查询综合门诊 列表")
    @Log(dataBase = false, printBody = false, printQuery = true)
    @GetMapping("/list")
    public APIResponse<PageInfo<PolyclinicListPcVO>> list(@Valid PolyclinicQueryParam queryParam) {
        PageDomain.startPage();
        List<PolyclinicListPcVO> list = polyclinicSV.selectListPC(queryParam);
        return successPage(list);
    }

    @ApiOperation("获取综合门诊 详细信息")
    @Log(dataBase = false, printBody = false, printQuery = true)
    @GetMapping(value = "/info")
    public APIResponse<PolyclinicEntity> info(@RequestParam Long id) {
        PolyclinicEntity data = polyclinicSV.selectById(id);
        return successData(data);
    }

    @ApiOperation("新增综合门诊 ")
    @Log(printQuery = false)
    @PostMapping("/insert")
    public APIResponse insert(@RequestBody @Validated(value = Add.class) PolyclinicUpdateParam updateParam) {
        Long id = polyclinicSV.insertPC(updateParam);
        return successData(id);
    }

    @ApiOperation("修改综合门诊 ")
    @Log(printQuery = false)
    @PostMapping("/update")
    public APIResponse update(@RequestBody @Validated(value = Update.class) PolyclinicUpdateParam updateParam) {
        int result = polyclinicSV.updateByIdPC(updateParam);
        return successData(result);
    }

    @ApiOperation("删除综合门诊 ")
    @Log(printQuery = false)
    @PostMapping("/delete")
    public APIResponse delete(@RequestBody @Valid @NotNull Long[] ids) {
        polyclinicSV.delete(ids);
        return success();
    }
}
